package jdbc;

import bean.DbInfo;

import java.sql.ResultSet;
import java.sql.SQLException;

public class RunConn {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        DbInfo dbInfo = new DbInfo();
        dbInfo.setIP("127.0.0.1");
        dbInfo.setPort(8080);
        dbInfo.setUsername("root");
        dbInfo.setPassword("808080ZhuZhaoYu#");
        dbInfo.setDatabase("test");
        dbInfo.setTable("user");

        Conn conn = new Conn(dbInfo);

        ResultSet rs = conn.query("select * from user");

        //查询，返回的内容就是结果集
        while(rs.next()) {
            int id=rs.getInt("id");
            System.out.println(id);
            String name=rs.getString("name");
            System.out.println(name);
            int age=rs.getInt("age");
            System.out.println(age);
        }

        //插入
        conn.insert("insert into user value(16,'中德',555)");

        //修改
        conn.update("update user set name='ZZTD' where id=1");

        //删除
        conn.delete("delete from user where id=1");
    }
}
